// @flow
import React, { Component } from 'react'
import { Icon } from 'antd'
import { GlobalTabs } from './GlobalTabs'
import { withRouter } from 'react-router'
import styles from './GlobalSearch.css'
import { saveGroupId, saveDeviceData } from 'store/modules/deviceCard'
import { connect } from 'react-redux'

type Props = {
  saveGroupId: Function,
  saveDeviceData: Function,
  history: Object
}
type State = {
  show: boolean
}

export class GlobalSearch extends Component {
  props: Props
  state: State

  open: () => void
  close: () => void

  constructor (props: Props) {
    super(props)

    this.state = {
      show: false
    }

    this.open = this.open.bind(this)
    this.close = this.close.bind(this)
  }

  componentDidMount () {
    // this.focusInput()
  }

  componentDidUpdate () {
    // this.focusInput()
  }

  open () {
    this.setState({
      show: !this.state.show
    })
  }

  close () {
    this.setState({
      show: false
    })
  }

  render () {
    const { history, saveGroupId, saveDeviceData } = this.props
    return (
      <div className={styles['search']}>
        <Icon type='search' onMouseOver={this.open} />
        { this.state.show && <div className={styles['bgFixed']} onMouseOver={this.close} >ss</div>}
        { this.state.show && <div className={styles['content']}>
          <div className={styles['bar-wrapper']}>
            <div className={styles['bar']}>
              {
                <GlobalTabs
                  history={history} saveGroupId={saveGroupId} saveDeviceData={saveDeviceData} close={this.close} />
              }
            </div>
          </div>
        </div>
        }
      </div>
    )
  }
}

const mapStatesToProps = (state) => {
  return {}
}
export default connect(mapStatesToProps, { saveGroupId, saveDeviceData })(withRouter(GlobalSearch))
